Skip to content

fix(cmake): prioritize discovered zlib headers for brpc sources - #23

Merged
zchuango merged 1 commit into
LinQuickDev:fix/cmake-zlib-include-orderfrom
BGQ99:fix/cmake-zlib-include-order
Aug 22, 2026
Merged

fix(cmake): prioritize discovered zlib headers for brpc sources#23
zchuango merged 1 commit into
LinQuickDev:fix/cmake-zlib-include-orderfrom
BGQ99:fix/cmake-zlib-include-order

Conversation

@BGQ99

@BGQ99 BGQ99 commented Aug 22, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: resolve 2593

Problem Summary:

When brpc is integrated into a parent CMake project with add_subdirectory, include directories from the parent project may be inherited by brpc targets. If the parent project adds an include directory that contains an unrelated zlib.h, such as Crypto++'s zlib.h, protobuf's gzip_stream.h may resolve that header instead of the actual zlib header.

This can cause compilation errors like:

/usr/include/google/protobuf/io/gzip_stream.h:93:3: error: 'z_stream' does not name a type

What is changed and the side effects?

Changed:

  • Explicitly find zlib with find_package(ZLIB REQUIRED).
  • Link with the standard ZLIB::ZLIB target instead of the bare z library name.
  • Prioritize the discovered zlib include directories for SOURCES_LIB, so protobuf's gzip_stream.h resolves the intended zlib header before inherited parent include directories.

Side effects:

  • Performance effects:

  • Breaking backward compatibility:


Check List:

Explicitly discover zlib and use the ZLIB::ZLIB target instead of the bare z library name.

Place the discovered zlib include directories before include paths inherited from parent projects when compiling SOURCES_LIB. This prevents protobuf's gzip_stream.h from resolving an unrelated zlib.h, such as the header provided by Crypto++.

This keeps standalone builds working while fixing add_subdirectory integration with dependency prefixes such as vcpkg.
@zchuango
zchuango merged commit f8eeb3e into LinQuickDev:fix/cmake-zlib-include-order Aug 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants